package com.weixin.menu;

import net.sf.json.JSONObject;
import org.apache.http.client.ClientProtocolException;

import java.io.IOException;

import static com.weixin.utils.WeiXinUtil.doPostStr;

/**
 * Created by Administrator on 2018-01-16.
 */
public class CreatMenu {
    private static final String CREATE_MENU_URL=" https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN";

    /**
     *
     * 创建菜单
     *
     * @param token
     * @param menu
     * @return
     * @throws ClientProtocolException
     * @throws IOException
     */


    public static int createMenu(String token,String menu) throws ClientProtocolException, IOException {

        int result = 0;

         String url = CREATE_MENU_URL.replace("ACCESS_TOKEN", token);

         JSONObject jsonObject = doPostStr(url, menu);

         if(jsonObject != null){

             result = jsonObject.getInt("errcode");

         }

         return result;
     }
}
